package com.warframe.message;

import com.warframe.entity.message.Message;

import java.util.concurrent.ConcurrentLinkedQueue;

public class ExecuMsgQueue {

    private ConcurrentLinkedQueue<Message> messageQueue;

    private ExecuMsgQueue(){
        messageQueue = new ConcurrentLinkedQueue<>();
    }

    private static class SingletonHolder{
        private final static ExecuMsgQueue instance=new ExecuMsgQueue();
    }

    public static ExecuMsgQueue getInstance(){
        return ExecuMsgQueue.SingletonHolder.instance;
    }

    public ConcurrentLinkedQueue<Message> getMessageQueue() {
        return messageQueue;
    }

    public void setMessageQueue(ConcurrentLinkedQueue<Message> messageQueue) {
        this.messageQueue = messageQueue;
    }

    public Integer size(){
        return messageQueue.size();
    }

    public Boolean isEmpty() {
        return messageQueue.isEmpty();
    }

    /*
        取出队列头，并从队列中删除该元素
        @return 队列头
     */
    public Message poll(){
        return messageQueue.poll();
    }

    /*
        仅取出队列头，不对队列做操作
        @return 队列头
     */
    public Message peek(){
        return messageQueue.peek();
    }

    /*
        向队列中添加元素
     */
    public void add(Message message){
        messageQueue.add(message);
    }

    /*
        向队列中添加另一个队列的所有元素
     */
    public void add(ConcurrentLinkedQueue<Message> msgQueue){
        messageQueue.addAll(msgQueue);
    }

}
